package com.yc.ssm.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yc.ssm.bean.TypeInfo;
import com.yc.ssm.biz.ITypeInfoBiz;
import com.yc.ssm.util.StringUtil;
import com.yc.ssm.vo.ResultVO;


@RestController
@RequestMapping("/type")
public class TypeInfoController {
	@Autowired
	private ITypeInfoBiz typeInfoBiz;
	/**
	 * 添加类型的方法
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@PostMapping("/add")
	public ResultVO add(TypeInfo tf)throws IOException {
		int result = typeInfoBiz.add(tf);
		if(result > 0) {
			return new ResultVO(200,"成功");
		}
		return new ResultVO(500,"失败");
	}
	
	@PostMapping("/finds")
	public Map<String, Object> finds(@RequestParam Map<String,Object> map)throws IOException {
		return typeInfoBiz.findByPage(map);
	}
	
	@GetMapping("/findAll")
	public ResultVO findAll()throws IOException {
		List<TypeInfo> list = typeInfoBiz.finds();
		if(list == null || list.isEmpty()) {
			return new ResultVO(600,"暂无数据");
		}
		return new ResultVO(200,list);
	}
}